<?php


/**
 * Base class that represents a row from the 'event_requests' table.
 *
 *
 *
 * @package    propel.generator.rcp.om
 */
abstract class RcpBaseEventRequests extends BaseObject implements Persistent
{
    /**
     * Peer class name
     */
    const PEER = 'RcpEventRequestsPeer';

    /**
     * The Peer class.
     * Instance provides a convenient way of calling static methods on a class
     * that calling code may not be able to identify.
     * @var        RcpEventRequestsPeer
     */
    protected static $peer;

    /**
     * The flag var to prevent infinit loop in deep copy
     * @var       boolean
     */
    protected $startCopy = false;

    /**
     * The value for the id field.
     * @var        int
     */
    protected $id;

    /**
     * The value for the event_request_type_id field.
     * @var        int
     */
    protected $event_request_type_id;

    /**
     * The value for the status field.
     * @var        int
     */
    protected $status;

    /**
     * The value for the corporate_output field.
     * @var        boolean
     */
    protected $corporate_output;

    /**
     * The value for the work_off_date field.
     * @var        string
     */
    protected $work_off_date;

    /**
     * The value for the comment field.
     * @var        string
     */
    protected $comment;

    /**
     * The value for the recompense_type field.
     * @var        int
     */
    protected $recompense_type;

    /**
     * The value for the last_modified field.
     * @var        string
     */
    protected $last_modified;

    /**
     * The value for the created field.
     * Note: this column has a database default value of: '2014-07-17 09:55:27'
     * @var        string
     */
    protected $created;

    /**
     * @var        EventRequestTypes
     */
    protected $aEventRequestTypes;

    /**
     * @var        PropelObjectCollection|RcpEventRequestComments[] Collection to store aggregation of RcpEventRequestComments objects.
     */
    protected $collEventRequestCommentss;
    protected $collEventRequestCommentssPartial;

    /**
     * @var        PropelObjectCollection|RcpEventRequestHasCalendarEvent[] Collection to store aggregation of RcpEventRequestHasCalendarEvent objects.
     */
    protected $collEventRequestHasCalendarEvents;
    protected $collEventRequestHasCalendarEventsPartial;

    /**
     * @var        PropelObjectCollection|RcpEventRequestProposalFreeDay[] Collection to store aggregation of RcpEventRequestProposalFreeDay objects.
     */
    protected $collEventRequestProposalFreeDays;
    protected $collEventRequestProposalFreeDaysPartial;

    /**
     * @var        PropelObjectCollection|RcpViewCalendarEvents[] Collection to store aggregation of RcpViewCalendarEvents objects.
     */
    protected $collViewCalendarEventss;
    protected $collViewCalendarEventssPartial;

    /**
     * Flag to prevent endless save loop, if this object is referenced
     * by another object which falls in this transaction.
     * @var        boolean
     */
    protected $alreadyInSave = false;

    /**
     * Flag to prevent endless validation loop, if this object is referenced
     * by another object which falls in this transaction.
     * @var        boolean
     */
    protected $alreadyInValidation = false;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $eventRequestCommentssScheduledForDeletion = null;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $eventRequestHasCalendarEventsScheduledForDeletion = null;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $eventRequestProposalFreeDaysScheduledForDeletion = null;

    /**
     * An array of objects scheduled for deletion.
     * @var		PropelObjectCollection
     */
    protected $viewCalendarEventssScheduledForDeletion = null;

    /**
     * Applies default values to this object.
     * This method should be called from the object's constructor (or
     * equivalent initialization method).
     * @see        __construct()
     */
    public function applyDefaultValues()
    {
        $this->created = '2014-07-17 09:55:27';
    }

    /**
     * Initializes internal state of RcpBaseEventRequests object.
     * @see        applyDefaults()
     */
    public function __construct()
    {
        parent::__construct();
        $this->applyDefaultValues();
    }

    /**
     * Get the [id] column value.
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get the [event_request_type_id] column value.
     *
     * @return int
     */
    public function getEventRequestTypeId()
    {
        return $this->event_request_type_id;
    }

    /**
     * Get the [status] column value.
     *
     * @return int
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Get the [corporate_output] column value.
     *
     * @return boolean
     */
    public function getCorporateOutput()
    {
        return $this->corporate_output;
    }

    /**
     * Get the [work_off_date] column value.
     *
     * @return string
     */
    public function getWorkOffDate()
    {
        return $this->work_off_date;
    }

    /**
     * Get the [comment] column value.
     *
     * @return string
     */
    public function getComment()
    {
        return $this->comment;
    }

    /**
     * Get the [recompense_type] column value.
     *
     * @return int
     */
    public function getRecompenseType()
    {
        return $this->recompense_type;
    }

    /**
     * Get the [optionally formatted] temporal [last_modified] column value.
     *
     *
     * @param string $format The date/time format string (either date()-style or strftime()-style).
     *				 If format is null, then the raw DateTime object will be returned.
     * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null
     * @throws PropelException - if unable to parse/validate the date/time value.
     */
    public function getLastModified($format = 'Y-m-d H:i:s')
    {
        if ($this->last_modified === null) {
            return null;
        }


        try {
            $dt = new DateTime($this->last_modified);
        } catch (Exception $x) {
            throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->last_modified, true), $x);
        }

        if ($format === null) {
            // Because propel.useDateTimeClass is true, we return a DateTime object.
            return $dt;
        } elseif (strpos($format, '%') !== false) {
            return strftime($format, $dt->format('U'));
        } else {
            return $dt->format($format);
        }
    }

    /**
     * Get the [optionally formatted] temporal [created] column value.
     *
     *
     * @param string $format The date/time format string (either date()-style or strftime()-style).
     *				 If format is null, then the raw DateTime object will be returned.
     * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null
     * @throws PropelException - if unable to parse/validate the date/time value.
     */
    public function getCreated($format = 'Y-m-d H:i:s')
    {
        if ($this->created === null) {
            return null;
        }


        try {
            $dt = new DateTime($this->created);
        } catch (Exception $x) {
            throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created, true), $x);
        }

        if ($format === null) {
            // Because propel.useDateTimeClass is true, we return a DateTime object.
            return $dt;
        } elseif (strpos($format, '%') !== false) {
            return strftime($format, $dt->format('U'));
        } else {
            return $dt->format($format);
        }
    }

    /**
     * Set the value of [id] column.
     *
     * @param int $v new value
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function setId($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->id !== $v) {
            $this->id = $v;
            $this->modifiedColumns[] = RcpEventRequestsPeer::ID;
        }


        return $this;
    } // setId()

    /**
     * Set the value of [event_request_type_id] column.
     *
     * @param int $v new value
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function setEventRequestTypeId($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->event_request_type_id !== $v) {
            $this->event_request_type_id = $v;
            $this->modifiedColumns[] = RcpEventRequestsPeer::EVENT_REQUEST_TYPE_ID;
        }

        if ($this->aEventRequestTypes !== null && $this->aEventRequestTypes->getId() !== $v) {
            $this->aEventRequestTypes = null;
        }


        return $this;
    } // setEventRequestTypeId()

    /**
     * Set the value of [status] column.
     *
     * @param int $v new value
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function setStatus($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->status !== $v) {
            $this->status = $v;
            $this->modifiedColumns[] = RcpEventRequestsPeer::STATUS;
        }


        return $this;
    } // setStatus()

    /**
     * Sets the value of the [corporate_output] column.
     * Non-boolean arguments are converted using the following rules:
     *   * 1, '1', 'true',  'on',  and 'yes' are converted to boolean true
     *   * 0, '0', 'false', 'off', and 'no'  are converted to boolean false
     * Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
     *
     * @param boolean|integer|string $v The new value
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function setCorporateOutput($v)
    {
        if ($v !== null) {
            if (is_string($v)) {
                $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
            } else {
                $v = (boolean) $v;
            }
        }

        if ($this->corporate_output !== $v) {
            $this->corporate_output = $v;
            $this->modifiedColumns[] = RcpEventRequestsPeer::CORPORATE_OUTPUT;
        }


        return $this;
    } // setCorporateOutput()

    /**
     * Set the value of [work_off_date] column.
     *
     * @param string $v new value
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function setWorkOffDate($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->work_off_date !== $v) {
            $this->work_off_date = $v;
            $this->modifiedColumns[] = RcpEventRequestsPeer::WORK_OFF_DATE;
        }


        return $this;
    } // setWorkOffDate()

    /**
     * Set the value of [comment] column.
     *
     * @param string $v new value
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function setComment($v)
    {
        if ($v !== null) {
            $v = (string) $v;
        }

        if ($this->comment !== $v) {
            $this->comment = $v;
            $this->modifiedColumns[] = RcpEventRequestsPeer::COMMENT;
        }


        return $this;
    } // setComment()

    /**
     * Set the value of [recompense_type] column.
     *
     * @param int $v new value
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function setRecompenseType($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->recompense_type !== $v) {
            $this->recompense_type = $v;
            $this->modifiedColumns[] = RcpEventRequestsPeer::RECOMPENSE_TYPE;
        }


        return $this;
    } // setRecompenseType()

    /**
     * Sets the value of [last_modified] column to a normalized version of the date/time value specified.
     *
     * @param mixed $v string, integer (timestamp), or DateTime value.
     *               Empty strings are treated as null.
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function setLastModified($v)
    {
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
        if ($this->last_modified !== null || $dt !== null) {
            $currentDateAsString = ($this->last_modified !== null && $tmpDt = new DateTime($this->last_modified)) ? $tmpDt->format('Y-m-d H:i:s') : null;
            $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
            if ($currentDateAsString !== $newDateAsString) {
                $this->last_modified = $newDateAsString;
                $this->modifiedColumns[] = RcpEventRequestsPeer::LAST_MODIFIED;
            }
        } // if either are not null


        return $this;
    } // setLastModified()

    /**
     * Sets the value of [created] column to a normalized version of the date/time value specified.
     *
     * @param mixed $v string, integer (timestamp), or DateTime value.
     *               Empty strings are treated as null.
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function setCreated($v)
    {
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
        if ($this->created !== null || $dt !== null) {
            $currentDateAsString = ($this->created !== null && $tmpDt = new DateTime($this->created)) ? $tmpDt->format('Y-m-d H:i:s') : null;
            $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
            if ( ($currentDateAsString !== $newDateAsString) // normalized values don't match
                || ($dt->format('Y-m-d H:i:s') === '2014-07-17 09:55:27') // or the entered value matches the default
                 ) {
                $this->created = $newDateAsString;
                $this->modifiedColumns[] = RcpEventRequestsPeer::CREATED;
            }
        } // if either are not null


        return $this;
    } // setCreated()

    /**
     * Indicates whether the columns in this object are only set to default values.
     *
     * This method can be used in conjunction with isModified() to indicate whether an object is both
     * modified _and_ has some values set which are non-default.
     *
     * @return boolean Whether the columns in this object are only been set with default values.
     */
    public function hasOnlyDefaultValues()
    {
            if ($this->created !== '2014-07-17 09:55:27') {
                return false;
            }

        // otherwise, everything was equal, so return true
        return true;
    } // hasOnlyDefaultValues()

    /**
     * Hydrates (populates) the object variables with values from the database resultset.
     *
     * An offset (0-based "start column") is specified so that objects can be hydrated
     * with a subset of the columns in the resultset rows.  This is needed, for example,
     * for results of JOIN queries where the resultset row includes columns from two or
     * more tables.
     *
     * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
     * @param int $startcol 0-based offset column which indicates which restultset column to start with.
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
     * @return int             next starting column
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
     */
    public function hydrate($row, $startcol = 0, $rehydrate = false)
    {
        try {

            $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
            $this->event_request_type_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
            $this->status = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
            $this->corporate_output = ($row[$startcol + 3] !== null) ? (boolean) $row[$startcol + 3] : null;
            $this->work_off_date = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
            $this->comment = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
            $this->recompense_type = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
            $this->last_modified = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
            $this->created = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
            $this->resetModified();

            $this->setNew(false);

            if ($rehydrate) {
                $this->ensureConsistency();
            }

            return $startcol + 9; // 9 = RcpEventRequestsPeer::NUM_HYDRATE_COLUMNS.

        } catch (Exception $e) {
            throw new PropelException("Error populating RcpEventRequests object", $e);
        }
    }

    /**
     * Checks and repairs the internal consistency of the object.
     *
     * This method is executed after an already-instantiated object is re-hydrated
     * from the database.  It exists to check any foreign keys to make sure that
     * the objects related to the current object are correct based on foreign key.
     *
     * You can override this method in the stub class, but you should always invoke
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
     * in case your model changes.
     *
     * @throws PropelException
     */
    public function ensureConsistency()
    {

        if ($this->aEventRequestTypes !== null && $this->event_request_type_id !== $this->aEventRequestTypes->getId()) {
            $this->aEventRequestTypes = null;
        }
    } // ensureConsistency

    /**
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
     *
     * This will only work if the object has been saved and has a valid primary key set.
     *
     * @param boolean $deep (optional) Whether to also de-associated any related objects.
     * @param PropelPDO $con (optional) The PropelPDO connection to use.
     * @return void
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
     */
    public function reload($deep = false, PropelPDO $con = null)
    {
        if ($this->isDeleted()) {
            throw new PropelException("Cannot reload a deleted object.");
        }

        if ($this->isNew()) {
            throw new PropelException("Cannot reload an unsaved object.");
        }

        if ($con === null) {
            $con = Propel::getConnection(RcpEventRequestsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }

        // We don't need to alter the object instance pool; we're just modifying this instance
        // already in the pool.

        $stmt = RcpEventRequestsPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
        $row = $stmt->fetch(PDO::FETCH_NUM);
        $stmt->closeCursor();
        if (!$row) {
            throw new PropelException('Cannot find matching row in the database to reload object values.');
        }
        $this->hydrate($row, 0, true); // rehydrate

        if ($deep) {  // also de-associate any related objects?

            $this->aEventRequestTypes = null;
            $this->collEventRequestCommentss = null;

            $this->collEventRequestHasCalendarEvents = null;

            $this->collEventRequestProposalFreeDays = null;

            $this->collViewCalendarEventss = null;

        } // if (deep)
    }

    /**
     * Removes this object from datastore and sets delete attribute.
     *
     * @param PropelPDO $con
     * @return void
     * @throws PropelException
     * @throws Exception
     * @see        BaseObject::setDeleted()
     * @see        BaseObject::isDeleted()
     */
    public function delete(PropelPDO $con = null)
    {
        if ($this->isDeleted()) {
            throw new PropelException("This object has already been deleted.");
        }

        if ($con === null) {
            $con = Propel::getConnection(RcpEventRequestsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
        }

        $con->beginTransaction();
        try {
            $deleteQuery = RcpEventRequestsQuery::create()
                ->filterByPrimaryKey($this->getPrimaryKey());
            $ret = $this->preDelete($con);
            if ($ret) {
                $deleteQuery->delete($con);
                $this->postDelete($con);
                $con->commit();
                $this->setDeleted(true);
            } else {
                $con->commit();
            }
        } catch (Exception $e) {
            $con->rollBack();
            throw $e;
        }
    }

    /**
     * Persists this object to the database.
     *
     * If the object is new, it inserts it; otherwise an update is performed.
     * All modified related objects will also be persisted in the doSave()
     * method.  This method wraps all precipitate database operations in a
     * single transaction.
     *
     * @param PropelPDO $con
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     * @throws PropelException
     * @throws Exception
     * @see        doSave()
     */
    public function save(PropelPDO $con = null)
    {
        if ($this->isDeleted()) {
            throw new PropelException("You cannot save an object that has been deleted.");
        }

        if ($con === null) {
            $con = Propel::getConnection(RcpEventRequestsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
        }

        $con->beginTransaction();
        $isInsert = $this->isNew();
        try {
            $ret = $this->preSave($con);
            if ($isInsert) {
                $ret = $ret && $this->preInsert($con);
            } else {
                $ret = $ret && $this->preUpdate($con);
            }
            if ($ret) {
                $affectedRows = $this->doSave($con);
                if ($isInsert) {
                    $this->postInsert($con);
                } else {
                    $this->postUpdate($con);
                }
                $this->postSave($con);
                RcpEventRequestsPeer::addInstanceToPool($this);
            } else {
                $affectedRows = 0;
            }
            $con->commit();

            return $affectedRows;
        } catch (Exception $e) {
            $con->rollBack();
            throw $e;
        }
    }

    /**
     * Performs the work of inserting or updating the row in the database.
     *
     * If the object is new, it inserts it; otherwise an update is performed.
     * All related objects are also updated in this method.
     *
     * @param PropelPDO $con
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     * @throws PropelException
     * @see        save()
     */
    protected function doSave(PropelPDO $con)
    {
        $affectedRows = 0; // initialize var to track total num of affected rows
        if (!$this->alreadyInSave) {
            $this->alreadyInSave = true;

            // We call the save method on the following object(s) if they
            // were passed to this object by their coresponding set
            // method.  This object relates to these object(s) by a
            // foreign key reference.

            if ($this->aEventRequestTypes !== null) {
                if ($this->aEventRequestTypes->isModified() || $this->aEventRequestTypes->isNew()) {
                    $affectedRows += $this->aEventRequestTypes->save($con);
                }
                $this->setEventRequestTypes($this->aEventRequestTypes);
            }

            if ($this->isNew() || $this->isModified()) {
                // persist changes
                if ($this->isNew()) {
                    $this->doInsert($con);
                } else {
                    $this->doUpdate($con);
                }
                $affectedRows += 1;
                $this->resetModified();
            }

            if ($this->eventRequestCommentssScheduledForDeletion !== null) {
                if (!$this->eventRequestCommentssScheduledForDeletion->isEmpty()) {
                    RcpEventRequestCommentsQuery::create()
                        ->filterByPrimaryKeys($this->eventRequestCommentssScheduledForDeletion->getPrimaryKeys(false))
                        ->delete($con);
                    $this->eventRequestCommentssScheduledForDeletion = null;
                }
            }

            if ($this->collEventRequestCommentss !== null) {
                foreach ($this->collEventRequestCommentss as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            if ($this->eventRequestHasCalendarEventsScheduledForDeletion !== null) {
                if (!$this->eventRequestHasCalendarEventsScheduledForDeletion->isEmpty()) {
                    RcpEventRequestHasCalendarEventQuery::create()
                        ->filterByPrimaryKeys($this->eventRequestHasCalendarEventsScheduledForDeletion->getPrimaryKeys(false))
                        ->delete($con);
                    $this->eventRequestHasCalendarEventsScheduledForDeletion = null;
                }
            }

            if ($this->collEventRequestHasCalendarEvents !== null) {
                foreach ($this->collEventRequestHasCalendarEvents as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            if ($this->eventRequestProposalFreeDaysScheduledForDeletion !== null) {
                if (!$this->eventRequestProposalFreeDaysScheduledForDeletion->isEmpty()) {
                    RcpEventRequestProposalFreeDayQuery::create()
                        ->filterByPrimaryKeys($this->eventRequestProposalFreeDaysScheduledForDeletion->getPrimaryKeys(false))
                        ->delete($con);
                    $this->eventRequestProposalFreeDaysScheduledForDeletion = null;
                }
            }

            if ($this->collEventRequestProposalFreeDays !== null) {
                foreach ($this->collEventRequestProposalFreeDays as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            if ($this->viewCalendarEventssScheduledForDeletion !== null) {
                if (!$this->viewCalendarEventssScheduledForDeletion->isEmpty()) {
                    foreach ($this->viewCalendarEventssScheduledForDeletion as $viewCalendarEvents) {
                        // need to save related object because we set the relation to null
                        $viewCalendarEvents->save($con);
                    }
                    $this->viewCalendarEventssScheduledForDeletion = null;
                }
            }

            if ($this->collViewCalendarEventss !== null) {
                foreach ($this->collViewCalendarEventss as $referrerFK) {
                    if (!$referrerFK->isDeleted()) {
                        $affectedRows += $referrerFK->save($con);
                    }
                }
            }

            $this->alreadyInSave = false;

        }

        return $affectedRows;
    } // doSave()

    /**
     * Insert the row in the database.
     *
     * @param PropelPDO $con
     *
     * @throws PropelException
     * @see        doSave()
     */
    protected function doInsert(PropelPDO $con)
    {
        $this->modifiedColumns[] = RcpEventRequestsPeer::ID;
        $criteria = $this->buildCriteria();
        if ($criteria->keyContainsValue(RcpEventRequestsPeer::ID) ) {
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . RcpEventRequestsPeer::ID . ')');
        }
        // remove pkey col since this table uses auto-increment and passing a null value for it is not valid
        $criteria->remove(RcpEventRequestsPeer::ID);
        $pk = BasePeer::doInsert($criteria, $con);
        $this->setId($pk);  //[IMV] update autoincrement primary key
        $this->setNew(false);
    }

    /**
     * Update the row in the database.
     *
     * @param PropelPDO $con
     *
     * @see        doSave()
     */
    protected function doUpdate(PropelPDO $con)
    {
        $selectCriteria = $this->buildPkeyCriteria();
        $valuesCriteria = $this->buildCriteria();
        BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
    }

    /**
     * Array of ValidationFailed objects.
     * @var        array ValidationFailed[]
     */
    protected $validationFailures = array();

    /**
     * Gets any ValidationFailed objects that resulted from last call to validate().
     *
     *
     * @return array ValidationFailed[]
     * @see        validate()
     */
    public function getValidationFailures()
    {
        return $this->validationFailures;
    }

    /**
     * Validates the objects modified field values and all objects related to this table.
     *
     * If $columns is either a column name or an array of column names
     * only those columns are validated.
     *
     * @param mixed $columns Column name or an array of column names.
     * @return boolean Whether all columns pass validation.
     * @see        doValidate()
     * @see        getValidationFailures()
     */
    public function validate($columns = null)
    {
        $res = $this->doValidate($columns);
        if ($res === true) {
            $this->validationFailures = array();

            return true;
        } else {
            $this->validationFailures = $res;

            return false;
        }
    }

    /**
     * This function performs the validation work for complex object models.
     *
     * In addition to checking the current object, all related objects will
     * also be validated.  If all pass then <code>true</code> is returned; otherwise
     * an aggreagated array of ValidationFailed objects will be returned.
     *
     * @param array $columns Array of column names to validate.
     * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
     */
    protected function doValidate($columns = null)
    {
        if (!$this->alreadyInValidation) {
            $this->alreadyInValidation = true;
            $retval = null;

            $failureMap = array();


            // We call the validate method on the following object(s) if they
            // were passed to this object by their coresponding set
            // method.  This object relates to these object(s) by a
            // foreign key reference.

            if ($this->aEventRequestTypes !== null) {
                if (!$this->aEventRequestTypes->validate($columns)) {
                    $failureMap = array_merge($failureMap, $this->aEventRequestTypes->getValidationFailures());
                }
            }


            if (($retval = RcpEventRequestsPeer::doValidate($this, $columns)) !== true) {
                $failureMap = array_merge($failureMap, $retval);
            }


                if ($this->collEventRequestCommentss !== null) {
                    foreach ($this->collEventRequestCommentss as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }

                if ($this->collEventRequestHasCalendarEvents !== null) {
                    foreach ($this->collEventRequestHasCalendarEvents as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }

                if ($this->collEventRequestProposalFreeDays !== null) {
                    foreach ($this->collEventRequestProposalFreeDays as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }

                if ($this->collViewCalendarEventss !== null) {
                    foreach ($this->collViewCalendarEventss as $referrerFK) {
                        if (!$referrerFK->validate($columns)) {
                            $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                        }
                    }
                }


            $this->alreadyInValidation = false;
        }

        return (!empty($failureMap) ? $failureMap : true);
    }

    /**
     * Retrieves a field from the object by name passed in as a string.
     *
     * @param string $name name
     * @param string $type The type of fieldname the $name is of:
     *               one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     *               BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     *               Defaults to BasePeer::TYPE_PHPNAME
     * @return mixed Value of field.
     */
    public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
    {
        $pos = RcpEventRequestsPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
        $field = $this->getByPosition($pos);

        return $field;
    }

    /**
     * Retrieves a field from the object by Position as specified in the xml schema.
     * Zero-based.
     *
     * @param int $pos position in xml schema
     * @return mixed Value of field at $pos
     */
    public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getEventRequestTypeId();
                break;
            case 2:
                return $this->getStatus();
                break;
            case 3:
                return $this->getCorporateOutput();
                break;
            case 4:
                return $this->getWorkOffDate();
                break;
            case 5:
                return $this->getComment();
                break;
            case 6:
                return $this->getRecompenseType();
                break;
            case 7:
                return $this->getLastModified();
                break;
            case 8:
                return $this->getCreated();
                break;
            default:
                return null;
                break;
        } // switch()
    }

    /**
     * Exports the object as an array.
     *
     * You can specify the key type of the array by passing one of the class
     * type constants.
     *
     * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     *                    Defaults to BasePeer::TYPE_PHPNAME.
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
     * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
     *
     * @return array an associative array containing the field names (as keys) and field values
     */
    public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
    {
        if (isset($alreadyDumpedObjects['RcpEventRequests'][$this->getPrimaryKey()])) {
            return '*RECURSION*';
        }
        $alreadyDumpedObjects['RcpEventRequests'][$this->getPrimaryKey()] = true;
        $keys = RcpEventRequestsPeer::getFieldNames($keyType);
        $result = array(
            $keys[0] => $this->getId(),
            $keys[1] => $this->getEventRequestTypeId(),
            $keys[2] => $this->getStatus(),
            $keys[3] => $this->getCorporateOutput(),
            $keys[4] => $this->getWorkOffDate(),
            $keys[5] => $this->getComment(),
            $keys[6] => $this->getRecompenseType(),
            $keys[7] => $this->getLastModified(),
            $keys[8] => $this->getCreated(),
        );
        if ($includeForeignObjects) {
            if (null !== $this->aEventRequestTypes) {
                $result['EventRequestTypes'] = $this->aEventRequestTypes->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
            }
            if (null !== $this->collEventRequestCommentss) {
                $result['EventRequestCommentss'] = $this->collEventRequestCommentss->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
            if (null !== $this->collEventRequestHasCalendarEvents) {
                $result['EventRequestHasCalendarEvents'] = $this->collEventRequestHasCalendarEvents->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
            if (null !== $this->collEventRequestProposalFreeDays) {
                $result['EventRequestProposalFreeDays'] = $this->collEventRequestProposalFreeDays->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
            if (null !== $this->collViewCalendarEventss) {
                $result['ViewCalendarEventss'] = $this->collViewCalendarEventss->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
            }
        }

        return $result;
    }

    /**
     * Sets a field from the object by name passed in as a string.
     *
     * @param string $name peer name
     * @param mixed $value field value
     * @param string $type The type of fieldname the $name is of:
     *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     *                     Defaults to BasePeer::TYPE_PHPNAME
     * @return void
     */
    public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
    {
        $pos = RcpEventRequestsPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);

        $this->setByPosition($pos, $value);
    }

    /**
     * Sets a field from the object by Position as specified in the xml schema.
     * Zero-based.
     *
     * @param int $pos position in xml schema
     * @param mixed $value field value
     * @return void
     */
    public function setByPosition($pos, $value)
    {
        switch ($pos) {
            case 0:
                $this->setId($value);
                break;
            case 1:
                $this->setEventRequestTypeId($value);
                break;
            case 2:
                $this->setStatus($value);
                break;
            case 3:
                $this->setCorporateOutput($value);
                break;
            case 4:
                $this->setWorkOffDate($value);
                break;
            case 5:
                $this->setComment($value);
                break;
            case 6:
                $this->setRecompenseType($value);
                break;
            case 7:
                $this->setLastModified($value);
                break;
            case 8:
                $this->setCreated($value);
                break;
        } // switch()
    }

    /**
     * Populates the object using an array.
     *
     * This is particularly useful when populating an object from one of the
     * request arrays (e.g. $_POST).  This method goes through the column
     * names, checking to see whether a matching key exists in populated
     * array. If so the setByName() method is called for that column.
     *
     * You can specify the key type of the array by additionally passing one
     * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     * The default key type is the column's BasePeer::TYPE_PHPNAME
     *
     * @param array  $arr     An array to populate the object from.
     * @param string $keyType The type of keys the array uses.
     * @return void
     */
    public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
    {
        $keys = RcpEventRequestsPeer::getFieldNames($keyType);

        if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
        if (array_key_exists($keys[1], $arr)) $this->setEventRequestTypeId($arr[$keys[1]]);
        if (array_key_exists($keys[2], $arr)) $this->setStatus($arr[$keys[2]]);
        if (array_key_exists($keys[3], $arr)) $this->setCorporateOutput($arr[$keys[3]]);
        if (array_key_exists($keys[4], $arr)) $this->setWorkOffDate($arr[$keys[4]]);
        if (array_key_exists($keys[5], $arr)) $this->setComment($arr[$keys[5]]);
        if (array_key_exists($keys[6], $arr)) $this->setRecompenseType($arr[$keys[6]]);
        if (array_key_exists($keys[7], $arr)) $this->setLastModified($arr[$keys[7]]);
        if (array_key_exists($keys[8], $arr)) $this->setCreated($arr[$keys[8]]);
    }

    /**
     * Build a Criteria object containing the values of all modified columns in this object.
     *
     * @return Criteria The Criteria object containing all modified values.
     */
    public function buildCriteria()
    {
        $criteria = new Criteria(RcpEventRequestsPeer::DATABASE_NAME);

        if ($this->isColumnModified(RcpEventRequestsPeer::ID)) $criteria->add(RcpEventRequestsPeer::ID, $this->id);
        if ($this->isColumnModified(RcpEventRequestsPeer::EVENT_REQUEST_TYPE_ID)) $criteria->add(RcpEventRequestsPeer::EVENT_REQUEST_TYPE_ID, $this->event_request_type_id);
        if ($this->isColumnModified(RcpEventRequestsPeer::STATUS)) $criteria->add(RcpEventRequestsPeer::STATUS, $this->status);
        if ($this->isColumnModified(RcpEventRequestsPeer::CORPORATE_OUTPUT)) $criteria->add(RcpEventRequestsPeer::CORPORATE_OUTPUT, $this->corporate_output);
        if ($this->isColumnModified(RcpEventRequestsPeer::WORK_OFF_DATE)) $criteria->add(RcpEventRequestsPeer::WORK_OFF_DATE, $this->work_off_date);
        if ($this->isColumnModified(RcpEventRequestsPeer::COMMENT)) $criteria->add(RcpEventRequestsPeer::COMMENT, $this->comment);
        if ($this->isColumnModified(RcpEventRequestsPeer::RECOMPENSE_TYPE)) $criteria->add(RcpEventRequestsPeer::RECOMPENSE_TYPE, $this->recompense_type);
        if ($this->isColumnModified(RcpEventRequestsPeer::LAST_MODIFIED)) $criteria->add(RcpEventRequestsPeer::LAST_MODIFIED, $this->last_modified);
        if ($this->isColumnModified(RcpEventRequestsPeer::CREATED)) $criteria->add(RcpEventRequestsPeer::CREATED, $this->created);

        return $criteria;
    }

    /**
     * Builds a Criteria object containing the primary key for this object.
     *
     * Unlike buildCriteria() this method includes the primary key values regardless
     * of whether or not they have been modified.
     *
     * @return Criteria The Criteria object containing value(s) for primary key(s).
     */
    public function buildPkeyCriteria()
    {
        $criteria = new Criteria(RcpEventRequestsPeer::DATABASE_NAME);
        $criteria->add(RcpEventRequestsPeer::ID, $this->id);

        return $criteria;
    }

    /**
     * Returns the primary key for this object (row).
     * @return int
     */
    public function getPrimaryKey()
    {
        return $this->getId();
    }

    /**
     * Generic method to set the primary key (id column).
     *
     * @param  int $key Primary key.
     * @return void
     */
    public function setPrimaryKey($key)
    {
        $this->setId($key);
    }

    /**
     * Returns true if the primary key for this object is null.
     * @return boolean
     */
    public function isPrimaryKeyNull()
    {

        return null === $this->getId();
    }

    /**
     * Sets contents of passed object to values from current object.
     *
     * If desired, this method can also make copies of all associated (fkey referrers)
     * objects.
     *
     * @param object $copyObj An object of RcpEventRequests (or compatible) type.
     * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
     * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
     * @throws PropelException
     */
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
    {
        $copyObj->setEventRequestTypeId($this->getEventRequestTypeId());
        $copyObj->setStatus($this->getStatus());
        $copyObj->setCorporateOutput($this->getCorporateOutput());
        $copyObj->setWorkOffDate($this->getWorkOffDate());
        $copyObj->setComment($this->getComment());
        $copyObj->setRecompenseType($this->getRecompenseType());
        $copyObj->setLastModified($this->getLastModified());
        $copyObj->setCreated($this->getCreated());

        if ($deepCopy && !$this->startCopy) {
            // important: temporarily setNew(false) because this affects the behavior of
            // the getter/setter methods for fkey referrer objects.
            $copyObj->setNew(false);
            // store object hash to prevent cycle
            $this->startCopy = true;

            foreach ($this->getEventRequestCommentss() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addEventRequestComments($relObj->copy($deepCopy));
                }
            }

            foreach ($this->getEventRequestHasCalendarEvents() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addEventRequestHasCalendarEvent($relObj->copy($deepCopy));
                }
            }

            foreach ($this->getEventRequestProposalFreeDays() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addEventRequestProposalFreeDay($relObj->copy($deepCopy));
                }
            }

            foreach ($this->getViewCalendarEventss() as $relObj) {
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
                    $copyObj->addViewCalendarEvents($relObj->copy($deepCopy));
                }
            }

            //unflag object copy
            $this->startCopy = false;
        } // if ($deepCopy)

        if ($makeNew) {
            $copyObj->setNew(true);
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
        }
    }

    /**
     * Makes a copy of this object that will be inserted as a new row in table when saved.
     * It creates a new object filling in the simple attributes, but skipping any primary
     * keys that are defined for the table.
     *
     * If desired, this method can also make copies of all associated (fkey referrers)
     * objects.
     *
     * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
     * @return RcpEventRequests Clone of current object.
     * @throws PropelException
     */
    public function copy($deepCopy = false)
    {
        // we use get_class(), because this might be a subclass
        $clazz = get_class($this);
        $copyObj = new $clazz();
        $this->copyInto($copyObj, $deepCopy);

        return $copyObj;
    }

    /**
     * Returns a peer instance associated with this om.
     *
     * Since Peer classes are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     *
     * @return RcpEventRequestsPeer
     */
    public function getPeer()
    {
        if (self::$peer === null) {
            self::$peer = new RcpEventRequestsPeer();
        }

        return self::$peer;
    }

    /**
     * Declares an association between this object and a RcpEventRequestTypes object.
     *
     * @param             RcpEventRequestTypes $v
     * @return RcpEventRequests The current object (for fluent API support)
     * @throws PropelException
     */
    public function setEventRequestTypes(RcpEventRequestTypes $v = null)
    {
        if ($v === null) {
            $this->setEventRequestTypeId(NULL);
        } else {
            $this->setEventRequestTypeId($v->getId());
        }

        $this->aEventRequestTypes = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the RcpEventRequestTypes object, it will not be re-added.
        if ($v !== null) {
            $v->addEventRequests($this);
        }


        return $this;
    }


    /**
     * Get the associated RcpEventRequestTypes object
     *
     * @param PropelPDO $con Optional Connection object.
     * @return RcpEventRequestTypes The associated RcpEventRequestTypes object.
     * @throws PropelException
     */
    public function getEventRequestTypes(PropelPDO $con = null)
    {
        if ($this->aEventRequestTypes === null && ($this->event_request_type_id !== null)) {
            $this->aEventRequestTypes = RcpEventRequestTypesQuery::create()->findPk($this->event_request_type_id, $con);
            /* The following can be used additionally to
                guarantee the related object contains a reference
                to this object.  This level of coupling may, however, be
                undesirable since it could result in an only partially populated collection
                in the referenced object.
                $this->aEventRequestTypes->addEventRequestss($this);
             */
        }

        return $this->aEventRequestTypes;
    }


    /**
     * Initializes a collection based on the name of a relation.
     * Avoids crafting an 'init[$relationName]s' method name
     * that wouldn't work when StandardEnglishPluralizer is used.
     *
     * @param string $relationName The name of the relation to initialize
     * @return void
     */
    public function initRelation($relationName)
    {
        if ('EventRequestComments' == $relationName) {
            $this->initEventRequestCommentss();
        }
        if ('EventRequestHasCalendarEvent' == $relationName) {
            $this->initEventRequestHasCalendarEvents();
        }
        if ('EventRequestProposalFreeDay' == $relationName) {
            $this->initEventRequestProposalFreeDays();
        }
        if ('ViewCalendarEvents' == $relationName) {
            $this->initViewCalendarEventss();
        }
    }

    /**
     * Clears out the collEventRequestCommentss collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addEventRequestCommentss()
     */
    public function clearEventRequestCommentss()
    {
        $this->collEventRequestCommentss = null; // important to set this to null since that means it is uninitialized
        $this->collEventRequestCommentssPartial = null;
    }

    /**
     * reset is the collEventRequestCommentss collection loaded partially
     *
     * @return void
     */
    public function resetPartialEventRequestCommentss($v = true)
    {
        $this->collEventRequestCommentssPartial = $v;
    }

    /**
     * Initializes the collEventRequestCommentss collection.
     *
     * By default this just sets the collEventRequestCommentss collection to an empty array (like clearcollEventRequestCommentss());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initEventRequestCommentss($overrideExisting = true)
    {
        if (null !== $this->collEventRequestCommentss && !$overrideExisting) {
            return;
        }
        $this->collEventRequestCommentss = new PropelObjectCollection();
        $this->collEventRequestCommentss->setModel('RcpEventRequestComments');
    }

    /**
     * Gets an array of RcpEventRequestComments objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this RcpEventRequests is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|RcpEventRequestComments[] List of RcpEventRequestComments objects
     * @throws PropelException
     */
    public function getEventRequestCommentss($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collEventRequestCommentssPartial && !$this->isNew();
        if (null === $this->collEventRequestCommentss || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collEventRequestCommentss) {
                // return empty collection
                $this->initEventRequestCommentss();
            } else {
                $collEventRequestCommentss = RcpEventRequestCommentsQuery::create(null, $criteria)
                    ->filterByEventRequests($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collEventRequestCommentssPartial && count($collEventRequestCommentss)) {
                      $this->initEventRequestCommentss(false);

                      foreach($collEventRequestCommentss as $obj) {
                        if (false == $this->collEventRequestCommentss->contains($obj)) {
                          $this->collEventRequestCommentss->append($obj);
                        }
                      }

                      $this->collEventRequestCommentssPartial = true;
                    }

                    return $collEventRequestCommentss;
                }

                if($partial && $this->collEventRequestCommentss) {
                    foreach($this->collEventRequestCommentss as $obj) {
                        if($obj->isNew()) {
                            $collEventRequestCommentss[] = $obj;
                        }
                    }
                }

                $this->collEventRequestCommentss = $collEventRequestCommentss;
                $this->collEventRequestCommentssPartial = false;
            }
        }

        return $this->collEventRequestCommentss;
    }

    /**
     * Sets a collection of EventRequestComments objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $eventRequestCommentss A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setEventRequestCommentss(PropelCollection $eventRequestCommentss, PropelPDO $con = null)
    {
        $this->eventRequestCommentssScheduledForDeletion = $this->getEventRequestCommentss(new Criteria(), $con)->diff($eventRequestCommentss);

        foreach ($this->eventRequestCommentssScheduledForDeletion as $eventRequestCommentsRemoved) {
            $eventRequestCommentsRemoved->setEventRequests(null);
        }

        $this->collEventRequestCommentss = null;
        foreach ($eventRequestCommentss as $eventRequestComments) {
            $this->addEventRequestComments($eventRequestComments);
        }

        $this->collEventRequestCommentss = $eventRequestCommentss;
        $this->collEventRequestCommentssPartial = false;
    }

    /**
     * Returns the number of related RcpEventRequestComments objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related RcpEventRequestComments objects.
     * @throws PropelException
     */
    public function countEventRequestCommentss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collEventRequestCommentssPartial && !$this->isNew();
        if (null === $this->collEventRequestCommentss || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collEventRequestCommentss) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getEventRequestCommentss());
                }
                $query = RcpEventRequestCommentsQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByEventRequests($this)
                    ->count($con);
            }
        } else {
            return count($this->collEventRequestCommentss);
        }
    }

    /**
     * Method called to associate a RcpEventRequestComments object to this object
     * through the RcpEventRequestComments foreign key attribute.
     *
     * @param    RcpEventRequestComments $l RcpEventRequestComments
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function addEventRequestComments(RcpEventRequestComments $l)
    {
        if ($this->collEventRequestCommentss === null) {
            $this->initEventRequestCommentss();
            $this->collEventRequestCommentssPartial = true;
        }
        if (!$this->collEventRequestCommentss->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddEventRequestComments($l);
        }

        return $this;
    }

    /**
     * @param	EventRequestComments $eventRequestComments The eventRequestComments object to add.
     */
    protected function doAddEventRequestComments($eventRequestComments)
    {
        $this->collEventRequestCommentss[]= $eventRequestComments;
        $eventRequestComments->setEventRequests($this);
    }

    /**
     * @param	EventRequestComments $eventRequestComments The eventRequestComments object to remove.
     */
    public function removeEventRequestComments($eventRequestComments)
    {
        if ($this->getEventRequestCommentss()->contains($eventRequestComments)) {
            $this->collEventRequestCommentss->remove($this->collEventRequestCommentss->search($eventRequestComments));
            if (null === $this->eventRequestCommentssScheduledForDeletion) {
                $this->eventRequestCommentssScheduledForDeletion = clone $this->collEventRequestCommentss;
                $this->eventRequestCommentssScheduledForDeletion->clear();
            }
            $this->eventRequestCommentssScheduledForDeletion[]= $eventRequestComments;
            $eventRequestComments->setEventRequests(null);
        }
    }

    /**
     * Clears out the collEventRequestHasCalendarEvents collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addEventRequestHasCalendarEvents()
     */
    public function clearEventRequestHasCalendarEvents()
    {
        $this->collEventRequestHasCalendarEvents = null; // important to set this to null since that means it is uninitialized
        $this->collEventRequestHasCalendarEventsPartial = null;
    }

    /**
     * reset is the collEventRequestHasCalendarEvents collection loaded partially
     *
     * @return void
     */
    public function resetPartialEventRequestHasCalendarEvents($v = true)
    {
        $this->collEventRequestHasCalendarEventsPartial = $v;
    }

    /**
     * Initializes the collEventRequestHasCalendarEvents collection.
     *
     * By default this just sets the collEventRequestHasCalendarEvents collection to an empty array (like clearcollEventRequestHasCalendarEvents());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initEventRequestHasCalendarEvents($overrideExisting = true)
    {
        if (null !== $this->collEventRequestHasCalendarEvents && !$overrideExisting) {
            return;
        }
        $this->collEventRequestHasCalendarEvents = new PropelObjectCollection();
        $this->collEventRequestHasCalendarEvents->setModel('RcpEventRequestHasCalendarEvent');
    }

    /**
     * Gets an array of RcpEventRequestHasCalendarEvent objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this RcpEventRequests is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|RcpEventRequestHasCalendarEvent[] List of RcpEventRequestHasCalendarEvent objects
     * @throws PropelException
     */
    public function getEventRequestHasCalendarEvents($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collEventRequestHasCalendarEventsPartial && !$this->isNew();
        if (null === $this->collEventRequestHasCalendarEvents || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collEventRequestHasCalendarEvents) {
                // return empty collection
                $this->initEventRequestHasCalendarEvents();
            } else {
                $collEventRequestHasCalendarEvents = RcpEventRequestHasCalendarEventQuery::create(null, $criteria)
                    ->filterByEventRequests($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collEventRequestHasCalendarEventsPartial && count($collEventRequestHasCalendarEvents)) {
                      $this->initEventRequestHasCalendarEvents(false);

                      foreach($collEventRequestHasCalendarEvents as $obj) {
                        if (false == $this->collEventRequestHasCalendarEvents->contains($obj)) {
                          $this->collEventRequestHasCalendarEvents->append($obj);
                        }
                      }

                      $this->collEventRequestHasCalendarEventsPartial = true;
                    }

                    return $collEventRequestHasCalendarEvents;
                }

                if($partial && $this->collEventRequestHasCalendarEvents) {
                    foreach($this->collEventRequestHasCalendarEvents as $obj) {
                        if($obj->isNew()) {
                            $collEventRequestHasCalendarEvents[] = $obj;
                        }
                    }
                }

                $this->collEventRequestHasCalendarEvents = $collEventRequestHasCalendarEvents;
                $this->collEventRequestHasCalendarEventsPartial = false;
            }
        }

        return $this->collEventRequestHasCalendarEvents;
    }

    /**
     * Sets a collection of EventRequestHasCalendarEvent objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $eventRequestHasCalendarEvents A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setEventRequestHasCalendarEvents(PropelCollection $eventRequestHasCalendarEvents, PropelPDO $con = null)
    {
        $this->eventRequestHasCalendarEventsScheduledForDeletion = $this->getEventRequestHasCalendarEvents(new Criteria(), $con)->diff($eventRequestHasCalendarEvents);

        foreach ($this->eventRequestHasCalendarEventsScheduledForDeletion as $eventRequestHasCalendarEventRemoved) {
            $eventRequestHasCalendarEventRemoved->setEventRequests(null);
        }

        $this->collEventRequestHasCalendarEvents = null;
        foreach ($eventRequestHasCalendarEvents as $eventRequestHasCalendarEvent) {
            $this->addEventRequestHasCalendarEvent($eventRequestHasCalendarEvent);
        }

        $this->collEventRequestHasCalendarEvents = $eventRequestHasCalendarEvents;
        $this->collEventRequestHasCalendarEventsPartial = false;
    }

    /**
     * Returns the number of related RcpEventRequestHasCalendarEvent objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related RcpEventRequestHasCalendarEvent objects.
     * @throws PropelException
     */
    public function countEventRequestHasCalendarEvents(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collEventRequestHasCalendarEventsPartial && !$this->isNew();
        if (null === $this->collEventRequestHasCalendarEvents || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collEventRequestHasCalendarEvents) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getEventRequestHasCalendarEvents());
                }
                $query = RcpEventRequestHasCalendarEventQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByEventRequests($this)
                    ->count($con);
            }
        } else {
            return count($this->collEventRequestHasCalendarEvents);
        }
    }

    /**
     * Method called to associate a RcpEventRequestHasCalendarEvent object to this object
     * through the RcpEventRequestHasCalendarEvent foreign key attribute.
     *
     * @param    RcpEventRequestHasCalendarEvent $l RcpEventRequestHasCalendarEvent
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function addEventRequestHasCalendarEvent(RcpEventRequestHasCalendarEvent $l)
    {
        if ($this->collEventRequestHasCalendarEvents === null) {
            $this->initEventRequestHasCalendarEvents();
            $this->collEventRequestHasCalendarEventsPartial = true;
        }
        if (!$this->collEventRequestHasCalendarEvents->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddEventRequestHasCalendarEvent($l);
        }

        return $this;
    }

    /**
     * @param	EventRequestHasCalendarEvent $eventRequestHasCalendarEvent The eventRequestHasCalendarEvent object to add.
     */
    protected function doAddEventRequestHasCalendarEvent($eventRequestHasCalendarEvent)
    {
        $this->collEventRequestHasCalendarEvents[]= $eventRequestHasCalendarEvent;
        $eventRequestHasCalendarEvent->setEventRequests($this);
    }

    /**
     * @param	EventRequestHasCalendarEvent $eventRequestHasCalendarEvent The eventRequestHasCalendarEvent object to remove.
     */
    public function removeEventRequestHasCalendarEvent($eventRequestHasCalendarEvent)
    {
        if ($this->getEventRequestHasCalendarEvents()->contains($eventRequestHasCalendarEvent)) {
            $this->collEventRequestHasCalendarEvents->remove($this->collEventRequestHasCalendarEvents->search($eventRequestHasCalendarEvent));
            if (null === $this->eventRequestHasCalendarEventsScheduledForDeletion) {
                $this->eventRequestHasCalendarEventsScheduledForDeletion = clone $this->collEventRequestHasCalendarEvents;
                $this->eventRequestHasCalendarEventsScheduledForDeletion->clear();
            }
            $this->eventRequestHasCalendarEventsScheduledForDeletion[]= $eventRequestHasCalendarEvent;
            $eventRequestHasCalendarEvent->setEventRequests(null);
        }
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this EventRequests is new, it will return
     * an empty collection; or if this EventRequests has previously
     * been saved, it will retrieve related EventRequestHasCalendarEvents from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in EventRequests.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|RcpEventRequestHasCalendarEvent[] List of RcpEventRequestHasCalendarEvent objects
     */
    public function getEventRequestHasCalendarEventsJoinCalendarEvents($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = RcpEventRequestHasCalendarEventQuery::create(null, $criteria);
        $query->joinWith('CalendarEvents', $join_behavior);

        return $this->getEventRequestHasCalendarEvents($query, $con);
    }

    /**
     * Clears out the collEventRequestProposalFreeDays collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addEventRequestProposalFreeDays()
     */
    public function clearEventRequestProposalFreeDays()
    {
        $this->collEventRequestProposalFreeDays = null; // important to set this to null since that means it is uninitialized
        $this->collEventRequestProposalFreeDaysPartial = null;
    }

    /**
     * reset is the collEventRequestProposalFreeDays collection loaded partially
     *
     * @return void
     */
    public function resetPartialEventRequestProposalFreeDays($v = true)
    {
        $this->collEventRequestProposalFreeDaysPartial = $v;
    }

    /**
     * Initializes the collEventRequestProposalFreeDays collection.
     *
     * By default this just sets the collEventRequestProposalFreeDays collection to an empty array (like clearcollEventRequestProposalFreeDays());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initEventRequestProposalFreeDays($overrideExisting = true)
    {
        if (null !== $this->collEventRequestProposalFreeDays && !$overrideExisting) {
            return;
        }
        $this->collEventRequestProposalFreeDays = new PropelObjectCollection();
        $this->collEventRequestProposalFreeDays->setModel('RcpEventRequestProposalFreeDay');
    }

    /**
     * Gets an array of RcpEventRequestProposalFreeDay objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this RcpEventRequests is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|RcpEventRequestProposalFreeDay[] List of RcpEventRequestProposalFreeDay objects
     * @throws PropelException
     */
    public function getEventRequestProposalFreeDays($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collEventRequestProposalFreeDaysPartial && !$this->isNew();
        if (null === $this->collEventRequestProposalFreeDays || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collEventRequestProposalFreeDays) {
                // return empty collection
                $this->initEventRequestProposalFreeDays();
            } else {
                $collEventRequestProposalFreeDays = RcpEventRequestProposalFreeDayQuery::create(null, $criteria)
                    ->filterByEventRequests($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collEventRequestProposalFreeDaysPartial && count($collEventRequestProposalFreeDays)) {
                      $this->initEventRequestProposalFreeDays(false);

                      foreach($collEventRequestProposalFreeDays as $obj) {
                        if (false == $this->collEventRequestProposalFreeDays->contains($obj)) {
                          $this->collEventRequestProposalFreeDays->append($obj);
                        }
                      }

                      $this->collEventRequestProposalFreeDaysPartial = true;
                    }

                    return $collEventRequestProposalFreeDays;
                }

                if($partial && $this->collEventRequestProposalFreeDays) {
                    foreach($this->collEventRequestProposalFreeDays as $obj) {
                        if($obj->isNew()) {
                            $collEventRequestProposalFreeDays[] = $obj;
                        }
                    }
                }

                $this->collEventRequestProposalFreeDays = $collEventRequestProposalFreeDays;
                $this->collEventRequestProposalFreeDaysPartial = false;
            }
        }

        return $this->collEventRequestProposalFreeDays;
    }

    /**
     * Sets a collection of EventRequestProposalFreeDay objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $eventRequestProposalFreeDays A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setEventRequestProposalFreeDays(PropelCollection $eventRequestProposalFreeDays, PropelPDO $con = null)
    {
        $this->eventRequestProposalFreeDaysScheduledForDeletion = $this->getEventRequestProposalFreeDays(new Criteria(), $con)->diff($eventRequestProposalFreeDays);

        foreach ($this->eventRequestProposalFreeDaysScheduledForDeletion as $eventRequestProposalFreeDayRemoved) {
            $eventRequestProposalFreeDayRemoved->setEventRequests(null);
        }

        $this->collEventRequestProposalFreeDays = null;
        foreach ($eventRequestProposalFreeDays as $eventRequestProposalFreeDay) {
            $this->addEventRequestProposalFreeDay($eventRequestProposalFreeDay);
        }

        $this->collEventRequestProposalFreeDays = $eventRequestProposalFreeDays;
        $this->collEventRequestProposalFreeDaysPartial = false;
    }

    /**
     * Returns the number of related RcpEventRequestProposalFreeDay objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related RcpEventRequestProposalFreeDay objects.
     * @throws PropelException
     */
    public function countEventRequestProposalFreeDays(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collEventRequestProposalFreeDaysPartial && !$this->isNew();
        if (null === $this->collEventRequestProposalFreeDays || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collEventRequestProposalFreeDays) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getEventRequestProposalFreeDays());
                }
                $query = RcpEventRequestProposalFreeDayQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByEventRequests($this)
                    ->count($con);
            }
        } else {
            return count($this->collEventRequestProposalFreeDays);
        }
    }

    /**
     * Method called to associate a RcpEventRequestProposalFreeDay object to this object
     * through the RcpEventRequestProposalFreeDay foreign key attribute.
     *
     * @param    RcpEventRequestProposalFreeDay $l RcpEventRequestProposalFreeDay
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function addEventRequestProposalFreeDay(RcpEventRequestProposalFreeDay $l)
    {
        if ($this->collEventRequestProposalFreeDays === null) {
            $this->initEventRequestProposalFreeDays();
            $this->collEventRequestProposalFreeDaysPartial = true;
        }
        if (!$this->collEventRequestProposalFreeDays->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddEventRequestProposalFreeDay($l);
        }

        return $this;
    }

    /**
     * @param	EventRequestProposalFreeDay $eventRequestProposalFreeDay The eventRequestProposalFreeDay object to add.
     */
    protected function doAddEventRequestProposalFreeDay($eventRequestProposalFreeDay)
    {
        $this->collEventRequestProposalFreeDays[]= $eventRequestProposalFreeDay;
        $eventRequestProposalFreeDay->setEventRequests($this);
    }

    /**
     * @param	EventRequestProposalFreeDay $eventRequestProposalFreeDay The eventRequestProposalFreeDay object to remove.
     */
    public function removeEventRequestProposalFreeDay($eventRequestProposalFreeDay)
    {
        if ($this->getEventRequestProposalFreeDays()->contains($eventRequestProposalFreeDay)) {
            $this->collEventRequestProposalFreeDays->remove($this->collEventRequestProposalFreeDays->search($eventRequestProposalFreeDay));
            if (null === $this->eventRequestProposalFreeDaysScheduledForDeletion) {
                $this->eventRequestProposalFreeDaysScheduledForDeletion = clone $this->collEventRequestProposalFreeDays;
                $this->eventRequestProposalFreeDaysScheduledForDeletion->clear();
            }
            $this->eventRequestProposalFreeDaysScheduledForDeletion[]= $eventRequestProposalFreeDay;
            $eventRequestProposalFreeDay->setEventRequests(null);
        }
    }

    /**
     * Clears out the collViewCalendarEventss collection
     *
     * This does not modify the database; however, it will remove any associated objects, causing
     * them to be refetched by subsequent calls to accessor method.
     *
     * @return void
     * @see        addViewCalendarEventss()
     */
    public function clearViewCalendarEventss()
    {
        $this->collViewCalendarEventss = null; // important to set this to null since that means it is uninitialized
        $this->collViewCalendarEventssPartial = null;
    }

    /**
     * reset is the collViewCalendarEventss collection loaded partially
     *
     * @return void
     */
    public function resetPartialViewCalendarEventss($v = true)
    {
        $this->collViewCalendarEventssPartial = $v;
    }

    /**
     * Initializes the collViewCalendarEventss collection.
     *
     * By default this just sets the collViewCalendarEventss collection to an empty array (like clearcollViewCalendarEventss());
     * however, you may wish to override this method in your stub class to provide setting appropriate
     * to your application -- for example, setting the initial array to the values stored in database.
     *
     * @param boolean $overrideExisting If set to true, the method call initializes
     *                                        the collection even if it is not empty
     *
     * @return void
     */
    public function initViewCalendarEventss($overrideExisting = true)
    {
        if (null !== $this->collViewCalendarEventss && !$overrideExisting) {
            return;
        }
        $this->collViewCalendarEventss = new PropelObjectCollection();
        $this->collViewCalendarEventss->setModel('RcpViewCalendarEvents');
    }

    /**
     * Gets an array of RcpViewCalendarEvents objects which contain a foreign key that references this object.
     *
     * If the $criteria is not null, it is used to always fetch the results from the database.
     * Otherwise the results are fetched from the database the first time, then cached.
     * Next time the same method is called without $criteria, the cached collection is returned.
     * If this RcpEventRequests is new, it will return
     * an empty collection or the current collection; the criteria is ignored on a new object.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @return PropelObjectCollection|RcpViewCalendarEvents[] List of RcpViewCalendarEvents objects
     * @throws PropelException
     */
    public function getViewCalendarEventss($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collViewCalendarEventssPartial && !$this->isNew();
        if (null === $this->collViewCalendarEventss || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collViewCalendarEventss) {
                // return empty collection
                $this->initViewCalendarEventss();
            } else {
                $collViewCalendarEventss = RcpViewCalendarEventsQuery::create(null, $criteria)
                    ->filterByEventRequests($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collViewCalendarEventssPartial && count($collViewCalendarEventss)) {
                      $this->initViewCalendarEventss(false);

                      foreach($collViewCalendarEventss as $obj) {
                        if (false == $this->collViewCalendarEventss->contains($obj)) {
                          $this->collViewCalendarEventss->append($obj);
                        }
                      }

                      $this->collViewCalendarEventssPartial = true;
                    }

                    return $collViewCalendarEventss;
                }

                if($partial && $this->collViewCalendarEventss) {
                    foreach($this->collViewCalendarEventss as $obj) {
                        if($obj->isNew()) {
                            $collViewCalendarEventss[] = $obj;
                        }
                    }
                }

                $this->collViewCalendarEventss = $collViewCalendarEventss;
                $this->collViewCalendarEventssPartial = false;
            }
        }

        return $this->collViewCalendarEventss;
    }

    /**
     * Sets a collection of ViewCalendarEvents objects related by a one-to-many relationship
     * to the current object.
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
     * and new objects from the given Propel collection.
     *
     * @param PropelCollection $viewCalendarEventss A Propel collection.
     * @param PropelPDO $con Optional connection object
     */
    public function setViewCalendarEventss(PropelCollection $viewCalendarEventss, PropelPDO $con = null)
    {
        $this->viewCalendarEventssScheduledForDeletion = $this->getViewCalendarEventss(new Criteria(), $con)->diff($viewCalendarEventss);

        foreach ($this->viewCalendarEventssScheduledForDeletion as $viewCalendarEventsRemoved) {
            $viewCalendarEventsRemoved->setEventRequests(null);
        }

        $this->collViewCalendarEventss = null;
        foreach ($viewCalendarEventss as $viewCalendarEvents) {
            $this->addViewCalendarEvents($viewCalendarEvents);
        }

        $this->collViewCalendarEventss = $viewCalendarEventss;
        $this->collViewCalendarEventssPartial = false;
    }

    /**
     * Returns the number of related RcpViewCalendarEvents objects.
     *
     * @param Criteria $criteria
     * @param boolean $distinct
     * @param PropelPDO $con
     * @return int             Count of related RcpViewCalendarEvents objects.
     * @throws PropelException
     */
    public function countViewCalendarEventss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    {
        $partial = $this->collViewCalendarEventssPartial && !$this->isNew();
        if (null === $this->collViewCalendarEventss || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collViewCalendarEventss) {
                return 0;
            } else {
                if($partial && !$criteria) {
                    return count($this->getViewCalendarEventss());
                }
                $query = RcpViewCalendarEventsQuery::create(null, $criteria);
                if ($distinct) {
                    $query->distinct();
                }

                return $query
                    ->filterByEventRequests($this)
                    ->count($con);
            }
        } else {
            return count($this->collViewCalendarEventss);
        }
    }

    /**
     * Method called to associate a RcpViewCalendarEvents object to this object
     * through the RcpViewCalendarEvents foreign key attribute.
     *
     * @param    RcpViewCalendarEvents $l RcpViewCalendarEvents
     * @return RcpEventRequests The current object (for fluent API support)
     */
    public function addViewCalendarEvents(RcpViewCalendarEvents $l)
    {
        if ($this->collViewCalendarEventss === null) {
            $this->initViewCalendarEventss();
            $this->collViewCalendarEventssPartial = true;
        }
        if (!$this->collViewCalendarEventss->contains($l)) { // only add it if the **same** object is not already associated
            $this->doAddViewCalendarEvents($l);
        }

        return $this;
    }

    /**
     * @param	ViewCalendarEvents $viewCalendarEvents The viewCalendarEvents object to add.
     */
    protected function doAddViewCalendarEvents($viewCalendarEvents)
    {
        $this->collViewCalendarEventss[]= $viewCalendarEvents;
        $viewCalendarEvents->setEventRequests($this);
    }

    /**
     * @param	ViewCalendarEvents $viewCalendarEvents The viewCalendarEvents object to remove.
     */
    public function removeViewCalendarEvents($viewCalendarEvents)
    {
        if ($this->getViewCalendarEventss()->contains($viewCalendarEvents)) {
            $this->collViewCalendarEventss->remove($this->collViewCalendarEventss->search($viewCalendarEvents));
            if (null === $this->viewCalendarEventssScheduledForDeletion) {
                $this->viewCalendarEventssScheduledForDeletion = clone $this->collViewCalendarEventss;
                $this->viewCalendarEventssScheduledForDeletion->clear();
            }
            $this->viewCalendarEventssScheduledForDeletion[]= $viewCalendarEvents;
            $viewCalendarEvents->setEventRequests(null);
        }
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this EventRequests is new, it will return
     * an empty collection; or if this EventRequests has previously
     * been saved, it will retrieve related ViewCalendarEventss from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in EventRequests.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|RcpViewCalendarEvents[] List of RcpViewCalendarEvents objects
     */
    public function getViewCalendarEventssJoinEventDefs($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = RcpViewCalendarEventsQuery::create(null, $criteria);
        $query->joinWith('EventDefs', $join_behavior);

        return $this->getViewCalendarEventss($query, $con);
    }


    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this EventRequests is new, it will return
     * an empty collection; or if this EventRequests has previously
     * been saved, it will retrieve related ViewCalendarEventss from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in EventRequests.
     *
     * @param Criteria $criteria optional Criteria object to narrow the query
     * @param PropelPDO $con optional connection object
     * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
     * @return PropelObjectCollection|RcpViewCalendarEvents[] List of RcpViewCalendarEvents objects
     */
    public function getViewCalendarEventssJoinUsers($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    {
        $query = RcpViewCalendarEventsQuery::create(null, $criteria);
        $query->joinWith('Users', $join_behavior);

        return $this->getViewCalendarEventss($query, $con);
    }

    /**
     * Clears the current object and sets all attributes to their default values
     */
    public function clear()
    {
        $this->id = null;
        $this->event_request_type_id = null;
        $this->status = null;
        $this->corporate_output = null;
        $this->work_off_date = null;
        $this->comment = null;
        $this->recompense_type = null;
        $this->last_modified = null;
        $this->created = null;
        $this->alreadyInSave = false;
        $this->alreadyInValidation = false;
        $this->clearAllReferences();
        $this->applyDefaultValues();
        $this->resetModified();
        $this->setNew(true);
        $this->setDeleted(false);
    }

    /**
     * Resets all references to other model objects or collections of model objects.
     *
     * This method is a user-space workaround for PHP's inability to garbage collect
     * objects with circular references (even in PHP 5.3). This is currently necessary
     * when using Propel in certain daemon or large-volumne/high-memory operations.
     *
     * @param boolean $deep Whether to also clear the references on all referrer objects.
     */
    public function clearAllReferences($deep = false)
    {
        if ($deep) {
            if ($this->collEventRequestCommentss) {
                foreach ($this->collEventRequestCommentss as $o) {
                    $o->clearAllReferences($deep);
                }
            }
            if ($this->collEventRequestHasCalendarEvents) {
                foreach ($this->collEventRequestHasCalendarEvents as $o) {
                    $o->clearAllReferences($deep);
                }
            }
            if ($this->collEventRequestProposalFreeDays) {
                foreach ($this->collEventRequestProposalFreeDays as $o) {
                    $o->clearAllReferences($deep);
                }
            }
            if ($this->collViewCalendarEventss) {
                foreach ($this->collViewCalendarEventss as $o) {
                    $o->clearAllReferences($deep);
                }
            }
        } // if ($deep)

        if ($this->collEventRequestCommentss instanceof PropelCollection) {
            $this->collEventRequestCommentss->clearIterator();
        }
        $this->collEventRequestCommentss = null;
        if ($this->collEventRequestHasCalendarEvents instanceof PropelCollection) {
            $this->collEventRequestHasCalendarEvents->clearIterator();
        }
        $this->collEventRequestHasCalendarEvents = null;
        if ($this->collEventRequestProposalFreeDays instanceof PropelCollection) {
            $this->collEventRequestProposalFreeDays->clearIterator();
        }
        $this->collEventRequestProposalFreeDays = null;
        if ($this->collViewCalendarEventss instanceof PropelCollection) {
            $this->collViewCalendarEventss->clearIterator();
        }
        $this->collViewCalendarEventss = null;
        $this->aEventRequestTypes = null;
    }

    /**
     * return the string representation of this object
     *
     * @return string
     */
    public function __toString()
    {
        return (string) $this->exportTo(RcpEventRequestsPeer::DEFAULT_STRING_FORMAT);
    }

    /**
     * return true is the object is in saving state
     *
     * @return boolean
     */
    public function isAlreadyInSave()
    {
        return $this->alreadyInSave;
    }

}
